﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;

using AddonService.Data;
using AddonService.DTO;
using System.Dynamic;
using Facebook;

namespace AddonService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AnnotService" in code, svc and config file together.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AnnotService : IAnnotService
    {
        
        public string AddNewAnnotation(Annotation annotation)
        {
            try
            {
                DataProvider.InsertAnnotation(annotation);
                var client = new FacebookClient("AAACzIehdvUEBAJqQVVhYy16tHIz8vCxghgizhaED4LjYb0r6vfSxxgwNAyhPX6UuJxmgZBbDOtSbtC9NzZBvf3ZA2v3qp9jeAQyCNteDubZCVKH16Lxx");
                var args = new Dictionary<string, object>();
                args["message"] = annotation.Content;
                args["link"] = annotation.Url;
                args["description "] = annotation.Comment;
                dynamic result = client.Post("/me/feed", args);
                return "Success";
            }
            catch (Exception e)
            {

            }
            return "Failed";
        }

        
        public List<Annotation> GetAllAnnotations()
        {
            try
            {
                return DataProvider.GetAllAnnotation();
                //return "Success";
            }
            catch (Exception e)
            {

            }
            return null;
        }

        
        public string DeleteAnnotation(DeleteUrl Url)
        {
            try
            {
                //Console.Write(Url);
                DataProvider.DeleteAnnotation(Url.url);                
                return "Success";
            }
            catch (Exception e)
            {

            }
            //return Url;
            return "Failed";
        }
    }
}
